const App = getApp();
const navigationBarHeight = (getApp().diygwstatusBarHeight + 44) + 'px'
Page({
    data: {
        tabs1: ['全部', '待支付', '已支付', '已完成'],
        activeIndex1: 0,
        scrollLeft: 0,

        msgs1: [],
        url: App.Config.basePath,
        je: 0
    },

    //弹出提示信息
    showModal(message) {
        App.WxService.showModal({
            title: '友情提示',
            content: message,
            showCancel: !1,
        });
    },
    onShareAppMessage: function () {
    },

    //页面加载
    onLoad(option) {
        if (option) {
            this.setData({
                globalOption: option
            })
        }
    },

    //页面显示
    onShow() {
        this.getMsgs1();

    },

    //页面跳转
    navigateTo(e) {
        App.navigateTo(e.currentTarget.dataset.url, e.currentTarget.dataset);
    },
    //tab切换事件
    tabClick1: function (e) {
        const dataset = e.currentTarget.dataset;
        this.setData({
            activeIndex1: dataset.id,
            scrollLeft: (e.currentTarget.dataset.id - 1) * 60
        });

        this.getMsgs1();
    },

    getMsgs1() {
        var mid = wx.getStorageSync("mid");

        if (mid == "") {
            this.setData({
                mid: 0,
                modalName:"Modal"
            })
        } else {
            //设置要传递的参数
            let param = {
                f: 1,
                t: this.data.activeIndex1,
                mid: wx.getStorageSync("mid"),
                loadmsg: `正在加载中`
            };

            App.HttpService.getData(param, "/orders_List").then(data => { //执行服务器Servlet
                this.setData({
                    msgs1: data //把从服务器端得到的值赋值给数组
                });
            });
        }
    },


    dele(e) {
        var that = this;
        const dataset = e.currentTarget.dataset;
        let param = {
            f: 1,
            id: dataset.id
        };
        App.WxService.showModal({
            title: '友情提示',
            content: '您确定要执行此操作吗？',
        }).then(data => {
            if (data.confirm == 1) {
                App.HttpService.delData(param, "/orders_Delete").then(data => {
                    App.WxService.showToast({
                        title: "操作成功!",
                        icon: 'success',
                        duration: 1500,
                    });
                    setTimeout(function () {
                        that.getMsgs1();
                    }, 1500)


                });
            }
        })
    },

    showModal(e) {
        this.setData({
            modalName: e.currentTarget.dataset.target,
            id: e.currentTarget.dataset.id,
            je: e.currentTarget.dataset.je
        })
    },
    hideModal(e) {
        this.setData({
            modalName: null
        })
    },

    pay(e) {
        var that = this;
        var data = null;

        data = App.Tools.extend(data, {
            f: 2,
            id: this.data.id,
        });

        App.HttpService.saveData(data, "/orders_Edit").then(data => {
            App.WxService.showToast({
                title: "支付成功!",
                icon: 'success',
                duration: 1500,
            });
            setTimeout(function () {
                that.setData({
                    modalName: null
                })
                that.getMsgs1();
            }, 1500)
        });
    },


    login(e)
    {
        var that=this;
        wx.getUserProfile({
            desc:'获取用户相关信息',
            success: res => {
                App.globalData.userInfo = res.userInfo
                console.log(App.globalData.userInfo);

                //调用数据
                let param = {
                    mname:App.globalData.userInfo.nickName,
                    addr:App.globalData.userInfo.avatarUrl
                };

                //调用数据
                App.HttpService.getData(param,"/members_Add").then(data=>{

                    wx.setStorageSync("mid",data[0].jieguo);

                    App.WxService.showToast({
                        title: "登录成功!",
                        icon: 'success',
                        duration: 1500,
                    });
                    setTimeout(function() {

                    }, 1500)

                    that.getMsgs1();
                    this.setData({
                        mid:-1,
                        modalName: null
                    })
                });


            }
        })
    },


})